package com.priox.sigar.application.job.mappers;

import com.priox.sigar.client.dto.GrupoEmpresarialDTO;
import org.apache.commons.lang.math.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.item.file.mapping.FieldSetMapper;
import org.springframework.batch.item.file.transform.FieldSet;
import org.springframework.stereotype.Component;
import org.springframework.validation.BindException;

/**
 * User: Matrix
 * Date: 10/02/13
 */
@Component
public class GrupoEmpresarialFieldSetMapper implements FieldSetMapper<GrupoEmpresarialDTO> {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());


    public GrupoEmpresarialDTO mapFieldSet(FieldSet fieldSet) throws BindException {
        GrupoEmpresarialDTO result = new GrupoEmpresarialDTO();
        System.out.println(fieldSet);
        if (NumberUtils.isNumber(fieldSet.readString(1))) {
            result.setNombre(fieldSet.readString(0));
            result.setSociedadId((fieldSet.readString(1)));
            result.setSociedadNombre(fieldSet.readString(2));
        }else{
            logger.error("El codigo de la sociedad no es numerico <"+fieldSet.readString(1)+">");
        }
        return result;
    }
}

